import QtQuick 2.2

//          编码规范
//        id
//        属性声明
//        信号声明
//        JavaScript 函数
//        对象属性
//        子对象
//        状态
//        过渡

Item {
   width: 600
   height: 600

   //Model
   ListModel {
       id: objModel
       Component.onCompleted: {
           objModel.append({"name":"Zero","level":0,"subNode":[]})
           objModel.append({"name":"One","level":0,"subNode":[]})
           objModel.append({"name":"Two","level":0,"subNode":[]})
           objModel.get(1).subNode.append({"name":"Three","level":1,"subNode":[]})
           objModel.get(1).subNode.append({"name":"Four","level":1,"subNode":[]})
           objModel.get(1).subNode.get(0).subNode.append({"name":"Five","level":2,"subNode":[]})
       }
   }

   //Delegate
   Component {
         id: objRecursiveDelegate
         Column {
            id: objRecursiveColumn
            MouseArea {
               width: objRow.implicitWidth
               height: objRow.implicitHeight
               Row {
                  id: objRow
                  Item {
                     height: 1
                     width: model.level * 20
                  }
                  Text {
                     text: (objRecursiveColumn.children.length > 2 ?
                              objRecursiveColumn.children[1].visible ?
                              qsTr("-  ") : qsTr("+ ") : qsTr("   ")) + model.name
                     color: objRecursiveColumn.children.length > 2 ? "blue" : "green"
                  }
               }
            }
            Repeater {
               model: subNode
               delegate: objRecursiveDelegate
            }
         }
      }

//View
      ListView {
         anchors.fill: parent
         model: objModel
         delegate: objRecursiveDelegate
      }
}
